package cc.surui.ui 
{
	import cc.surui.common.event.UIEventer;
	import cc.surui.logic.AppleRunner;
	import cc.surui.mc.Background;
	import cc.surui.ui.fl.UIScore;
	import cc.surui.ui.fl.UIStartButton;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	/**
	 * 游戏主界面
	 * @author Surui
	 */
	public class UIApple extends Sprite 
	{
		private var _startButton:UIStartButton = new UIStartButton();
		private var _uiScoreGet:UIScore = new UIScore(4);
		private var _uiScoreTotal:UIScore = new UIScore(7);
		public function UIApple() 
		{
			super();
		}
		
		public function init():void {
			// 添加游戏背景图
			var bg:Background = new Background();
			this.addChild(bg);
			bg.x = (800 - bg.width) / 2;
			
			// 添加开始按钮
			this.addChild(_startButton);
			_startButton.x = (800 - _startButton.width) / 2;
			_startButton.y = 540;
			_startButton.addEventListener(MouseEvent.CLICK, onStartButtonClick);
			
			// 初始化水果机转盘图标,设定坐标
			for (var i:int = 0; i < 24; i++ ) {
				AppleRunner.self.birds[i].light = false;
				this.addChild(AppleRunner.self.birds[i]);
				AppleRunner.self.birds[i].position = AppleRunner.self.places[i];
			}
			
			// 添加玩家分数成绩显示牌
			this.addChild(_uiScoreGet);
			_uiScoreGet.value = 123;
			_uiScoreGet.x = 65;
			_uiScoreGet.y = 485;
			this.addChild(_uiScoreTotal);
			_uiScoreTotal.value = 584;
			_uiScoreTotal.x = 565;
			_uiScoreTotal.y = 485;
		}
		
		private function onStartButtonClick( event:MouseEvent ):void {
			UIEventer.dispatch(UIEventer.START_BUTTON_CLICK);
		}
		
	}

}